package second.group.bering.parking_system

import second.group.bering.parking_system.model.Car
import spock.lang.Specification
import spock.lang.Unroll;
/**
 *
 * ParkingBoyTest
 *
 * @author Burgess Li, Thomas Chen
 * @date 8/23/2018 4:46 PM
 * @version 1.0
 *
 */
class ParkingBoyTest extends Specification {

    @Unroll
    def 'should return park details: #PARK_ID when input car: #CAR_NUMBER, parks: #PARKS'() {

        given:
        ParkingBoy parkManager = new ParkingBoy()
        PARKS.each { parkId, parkSize ->
            parkManager.addPark(new Park(id: parkId, size: parkSize))
        }

        expect:
        parkManager.parking(new Car(number: CAR_NUMBER)) == PARK_ID

        where:
        PARKS                       |   CAR_NUMBER      |     PARK_ID
        ['P1': 10, 'P2': 10]        |   'A123'          |     'P1'
        ['P1': 0, 'P2': 10]         |   'A123'          |     'P2'
        ['P1': 0, 'P2': 0]          |   'A123'          |     null

    }

    @Unroll
    def 'should return pickup car number: #PICKUP_CAR_NUMBER when input parks: #PARKS, car: #CAR_NUMBER, park id: #PARK_ID'() {

        given:
        ParkingBoy parkManager = new ParkingBoy()
        PARKS.each { parkId, parkCars ->
            parkManager.addPark(new Park(id: parkId, size: parkCars.size()))
            parkCars.each { currentCarNumber ->
                parkManager.parking(new Car(number: currentCarNumber))
            }
        }

        expect:
        parkManager.pickup(PARK_ID, CAR_NUMBER)?.number == PICKUP_CAR_NUMBER

        where:
        PARKS                                           |   CAR_NUMBER  |  PARK_ID   |     PICKUP_CAR_NUMBER
        ['P1': ['A123', 'A456'],'P2':['A211','A222']]   |   'A123'      |  'P1'      |     'A123'
        ['P1': ['A123', 'A456'],'P2':['A211','A222']]   |   'A211'      |  'P2'      |     'A211'
        ['P1': ['A123', 'A456'],'P2':['A211','A222']]   |   'A211'      |  'P1'      |     null
        ['P1': ['A123', 'A456'],'P2':['A211','A222']]   |   'A333'      |  'P1'      |     null

    }

}
